package com.demo.dao;



import com.demo.pojo.Branch;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @ClassName ItemDao
 * @Description TODO
 * @Author Windy
 * @Date 2022/8/25 14:32
 * @Version 1.0
 **/
public interface BranchDao {

    /**
     * 查询所有属于同一pid下的数据
     * @param pid 项目id
     * @return 多条符合条件的数据
     */
    @Select("select * from branch where pid=#{pid} and status=1")
    List<Branch> findBranchByPid(int pid);


    /**
     * 一个开发部门对应多个计划
     * @param pid
     * @return 返回项目对应的部门，同时获取该部门对应的所有计划
     */
    @Select("select * from branch where pid=#{pid} and status=1")
    @Results(id = "taskMap",value = {
            @Result(column = "bid",property = "bid"),
            @Result(column = "bname",property = "bname"),
            @Result(column = "pid",property = "pid"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "status",property = "status"),
            @Result(column = "bid",property = "taskPlans",
                    many = @Many(select = "com.demo.dao.TaskPlanDao.findTaskByBid")
            )
    })
    List<Branch> findBranchAndTaskByPid(int pid);

    /**
     * @return 获取所有的部门，并获取每个部门的所有计划
     */
    @Select("select * from branch where status=1")
    @ResultMap("taskMap")
    List<Branch> findAll();


}
